package StraightInsertionSort;
//直接插入排序

import java.util.Random;

public class Sort02 {
    public static void main(String[] args) {
        Random random = new Random();
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = random.nextInt(100);
        }
        for (int i : a) {
            System.out.print(i + "   ");
        }
        System.out.println();
        sort(a);
        for (int ints : a) {
            System.out.print(ints + "   ");
        }
    }
        public static void sort(int [] a)
        {
            int i,j,x;
            for(i=1;i<a.length;i++)
            {
                x=a[i];
                for(j=i-1;j>-1&&a[j]>x;a[j+1]=a[j],j--);
                a[j+1]=x;
            }
        }
}

